package com.ourteam.system.dao.impl;

import com.ourteam.system.dao.ISysEventLogDAO;
import com.ourteam.system.dao.SysEventLog;
import com.ourteam.system.dao.SysEventLogDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-07-31 15:13:39
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractSysEventLogDAOJdbcImpl extends AbstractSpringDAO
    implements ISysEventLogDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, EventLevel, EventTypeId, EventSource, EventContent, EventTime,
            EventOperator, EventOperatorId, EventOperatorClient, EventData,
            EventSourceId, EventTypeCode, EventTypeName, EventTypeStatus,
            EventDomainId, EventDomainCode, OperatorName
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.EventLevel,
            _DataObjectProperty.EventTypeId, _DataObjectProperty.EventSource,
            _DataObjectProperty.EventContent, _DataObjectProperty.EventTime,
            _DataObjectProperty.EventOperator,
            _DataObjectProperty.EventOperatorId,
            _DataObjectProperty.EventOperatorClient,
            _DataObjectProperty.EventData, _DataObjectProperty.EventSourceId,
            _DataObjectProperty.EventTypeCode, _DataObjectProperty.EventTypeName,
            _DataObjectProperty.EventTypeStatus,
            _DataObjectProperty.EventDomainId,
            _DataObjectProperty.EventDomainCode,
            _DataObjectProperty.OperatorName
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<SysEventLog, SysEventLogDAOQueryBean> daoHelper;

    public AbstractSysEventLogDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<SysEventLog, SysEventLogDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysEventLogTypeDAO.EntityName)
                                .append(" SYS_EVENT_LOG_TYPE ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysEventLogTypeDAO.Id,
                    com.ourteam.system.dao.ISysEventLogTypeDAO.EntityName +
                    ".", "SYS_EVENT_LOG_TYPE."));
            relatedJoinSQLBuffer.append(" = ").append(EventTypeId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysDomainDAO.EntityName)
                                .append(" SYS_DOMAIN ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysDomainDAO.Id,
                    com.ourteam.system.dao.ISysDomainDAO.EntityName + ".",
                    "SYS_DOMAIN."));
            relatedJoinSQLBuffer.append(" = ").append(EventDomainId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysUserDAO.EntityName)
                                .append(" operator_user ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysUserDAO.Id,
                    com.ourteam.system.dao.ISysUserDAO.EntityName + ".",
                    "operator_user."));
            relatedJoinSQLBuffer.append(" = ").append(EventOperatorId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aSysEventLog
         * @throws Exception
         */
    public boolean checkIsUnique(SysEventLog aSysEventLog)
        throws Exception {
        if (aSysEventLog == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aSysEventLog.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aSysEventLog
     * @throws Exception
     */
    public void insert(SysEventLog aSysEventLog) throws Exception {
        super.doInsert(aSysEventLog);
    }

    /**
         * Batch Insert Datas
         * @param aSysEventLog
         * @throws Exception
         */
    public void batchInsert(SysEventLog[] aSysEventLogs)
        throws Exception {
        super.doBatchInsert(aSysEventLogs);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(SysEventLogDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(SysEventLog aSysEventLog) throws Exception {
        delete(aSysEventLog.getId());
    }

    /**
     * Update Data Selective
     * @param aSysEventLog
     * @throws Exception
     */
    public void update(SysEventLog aSysEventLog) throws Exception {
        if (aSysEventLog.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aSysEventLog);

        SysEventLog tempObj = findById(aSysEventLog.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aSysEventLog, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aSysEventLogs[]
     * @throws Exception
     */
    public void batchUpdate(SysEventLog[] aSysEventLogs)
        throws Exception {
        super.doBatchUpdate(aSysEventLogs);
    }

    /**
         * Update Data By Condictions
         * @param aSysEventLog
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(SysEventLog aSysEventLog,
        SysEventLogDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aSysEventLog, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(SysEventLogDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(SysEventLog aSysEventLog)
        throws Exception {
        if (aSysEventLog.getEventLevel() == null) {
            throw new Exception(
                "The SysEventLog.eventLevel value is not allow NULL");
        }

        if (aSysEventLog.getEventSource() == null) {
            throw new Exception(
                "The SysEventLog.eventSource value is not allow NULL");
        }

        if (aSysEventLog.getEventContent() == null) {
            throw new Exception(
                "The SysEventLog.eventContent value is not allow NULL");
        }

        if (aSysEventLog.getEventTime() == null) {
            throw new Exception(
                "The SysEventLog.eventTime value is not allow NULL");
        }

        if (aSysEventLog.getEventOperator() == null) {
            throw new Exception(
                "The SysEventLog.eventOperator value is not allow NULL");
        }

        if (aSysEventLog.getEventOperatorClient() == null) {
            throw new Exception(
                "The SysEventLog.eventOperatorClient value is not allow NULL");
        }

        if (aSysEventLog.getEventTypeCode() == null) {
            throw new Exception(
                "The SysEventLog.eventTypeCode value is not allow NULL");
        }

        if (aSysEventLog.getEventTypeName() == null) {
            throw new Exception(
                "The SysEventLog.eventTypeName value is not allow NULL");
        }

        if (aSysEventLog.getEventTypeStatus() == null) {
            throw new Exception(
                "The SysEventLog.eventTypeStatus value is not allow NULL");
        }

        if (aSysEventLog.getEventData() == null) {
            throw new Exception(
                "The SysEventLog.eventData value is not allow NULL");
        }

        if (aSysEventLog.getOperatorName() == null) {
            throw new Exception(
                "The SysEventLog.operatorName value is not allow NULL");
        }

        if (aSysEventLog.getEventDomainCode() == null) {
            throw new Exception(
                "The SysEventLog.eventDomainCode value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public SysEventLog findById(final long id) throws Exception {
        SysEventLogDAOQueryBean queryBean = new SysEventLogDAOQueryBean();

        SysEventLogDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        SysEventLog[] SysEventLogs = query(queryBean);

        if (SysEventLogs.length == 0) {
            return null;
        } else {
            return SysEventLogs[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return SysEventLog[]
         * @throws Exception
         */
    public SysEventLog[] query(SysEventLogDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean, new JdbcSysEventLogRowMapper());

        return (SysEventLog[]) result.toArray(new SysEventLog[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        SysEventLogDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(SysEventLogDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(SysEventLog[] aSysEventLogs,
        SysEventLogDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aSysEventLogs, queryBean);
    }

    public void synchronize(SysEventLog[] aSysEventLogs,
        SysEventLogDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<SysEventLog> callBack)
        throws Exception {
        daoHelper.synchronize(aSysEventLogs, queryBean, callBack);
    }

    public static class JdbcSysEventLogRowMapper implements RowMapper<SysEventLog> {
        public SysEventLog mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            SysEventLog object = new SysEventLog();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object eventLevel = null;

                eventLevel = resultSet.getObject(columnIndex++);

                object.setEventLevelNull(resultSet.getBoolean(columnIndex++));

                if (eventLevel != null) {
                    setBeanValue(object, _DataObjectProperty.EventLevel,
                        eventLevel);
                }

                Object eventTypeId = null;

                eventTypeId = resultSet.getObject(columnIndex++);

                object.setEventTypeIdNull(resultSet.getBoolean(columnIndex++));

                if (eventTypeId != null) {
                    setBeanValue(object, _DataObjectProperty.EventTypeId,
                        eventTypeId);
                }

                Object eventSource = null;

                eventSource = resultSet.getObject(columnIndex++);

                object.setEventSourceNull(resultSet.getBoolean(columnIndex++));

                if (eventSource != null) {
                    setBeanValue(object, _DataObjectProperty.EventSource,
                        eventSource);
                }

                Object eventContent = null;

                eventContent = resultSet.getObject(columnIndex++);

                object.setEventContentNull(resultSet.getBoolean(columnIndex++));

                if (eventContent != null) {
                    setBeanValue(object, _DataObjectProperty.EventContent,
                        eventContent);
                }

                Object eventTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    eventTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    eventTime = resultSet.getObject(columnIndex++);
                }

                object.setEventTimeNull(resultSet.getBoolean(columnIndex++));

                if (eventTime != null) {
                    setBeanValue(object, _DataObjectProperty.EventTime,
                        eventTime);
                }

                Object eventOperator = null;

                eventOperator = resultSet.getObject(columnIndex++);

                object.setEventOperatorNull(resultSet.getBoolean(columnIndex++));

                if (eventOperator != null) {
                    setBeanValue(object, _DataObjectProperty.EventOperator,
                        eventOperator);
                }

                Object eventOperatorId = null;

                eventOperatorId = resultSet.getObject(columnIndex++);

                object.setEventOperatorIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (eventOperatorId != null) {
                    setBeanValue(object, _DataObjectProperty.EventOperatorId,
                        eventOperatorId);
                }

                Object eventOperatorClient = null;

                eventOperatorClient = resultSet.getObject(columnIndex++);

                object.setEventOperatorClientNull(resultSet.getBoolean(
                        columnIndex++));

                if (eventOperatorClient != null) {
                    setBeanValue(object,
                        _DataObjectProperty.EventOperatorClient,
                        eventOperatorClient);
                }

                Object eventData = null;

                eventData = resultSet.getObject(columnIndex++);

                object.setEventDataNull(resultSet.getBoolean(columnIndex++));

                if (eventData != null) {
                    setBeanValue(object, _DataObjectProperty.EventData,
                        eventData);
                }

                Object eventSourceId = null;

                eventSourceId = resultSet.getObject(columnIndex++);

                object.setEventSourceIdNull(resultSet.getBoolean(columnIndex++));

                if (eventSourceId != null) {
                    setBeanValue(object, _DataObjectProperty.EventSourceId,
                        eventSourceId);
                }

                Object eventTypeCode = null;

                eventTypeCode = resultSet.getObject(columnIndex++);

                object.setEventTypeCodeNull(resultSet.getBoolean(columnIndex++));

                if (eventTypeCode != null) {
                    setBeanValue(object, _DataObjectProperty.EventTypeCode,
                        eventTypeCode);
                }

                Object eventTypeName = null;

                eventTypeName = resultSet.getObject(columnIndex++);

                object.setEventTypeNameNull(resultSet.getBoolean(columnIndex++));

                if (eventTypeName != null) {
                    setBeanValue(object, _DataObjectProperty.EventTypeName,
                        eventTypeName);
                }

                Object eventTypeStatus = null;

                eventTypeStatus = resultSet.getObject(columnIndex++);

                object.setEventTypeStatusNull(resultSet.getBoolean(
                        columnIndex++));

                if (eventTypeStatus != null) {
                    setBeanValue(object, _DataObjectProperty.EventTypeStatus,
                        eventTypeStatus);
                }

                Object eventDomainId = null;

                eventDomainId = resultSet.getObject(columnIndex++);

                object.setEventDomainIdNull(resultSet.getBoolean(columnIndex++));

                if (eventDomainId != null) {
                    setBeanValue(object, _DataObjectProperty.EventDomainId,
                        eventDomainId);
                }

                Object eventDomainCode = null;

                eventDomainCode = resultSet.getObject(columnIndex++);

                object.setEventDomainCodeNull(resultSet.getBoolean(
                        columnIndex++));

                if (eventDomainCode != null) {
                    setBeanValue(object, _DataObjectProperty.EventDomainCode,
                        eventDomainCode);
                }

                Object operatorName = null;

                operatorName = resultSet.getObject(columnIndex++);

                object.setOperatorNameNull(resultSet.getBoolean(columnIndex++));

                if (operatorName != null) {
                    setBeanValue(object, _DataObjectProperty.OperatorName,
                        operatorName);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
